package com.yuan.SMS.controller;

import com.alibaba.fastjson.JSON;
import com.yuan.SMS.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class AgeCountController {
    @Autowired
    StudentDao ageCdao;

    @RequestMapping("/ageCount")
    @CrossOrigin("http://localhost:8080")
    public String ageCount(String age){
        System.out.println(age);
        int i = ageCdao.getStudentCounts();
        int j = ageCdao.getStudentCountsByAge(age);
        double perc = j/i;
        HashMap<String, Object> res = new HashMap<>();
        if(i!=0.00){
            res.put("flag","success");
            res.put("data",perc);
        }else{
            res.put("flag","error");
        }
        return JSON.toJSONString(res);
    }
}
